from flask import Flask, make_response, request, session
import datetime
import os
app = Flask(__name__)
#  启用session
app.config['SECRET_KEY'] = os.urandom(24)  # 生成随机数种子，用于生成sessionId


@app.route("/login")
def login():
    session["isLogin"] = True

    return "登录成功"


@app.route("/update_user")
def update_user():
    return "修改用户信息成功"

# 全局拦截器，不管是谁统统拦截
@app.before_request
def before():
    # 获取用户的url，然后根据url进行判断，哪些拦截，哪些不拦截
    url = request.path
    print(url)
    if url == "/login":
        # return "登录成功了，我得放行了"
        pass
    else:
        if_login = session.get("isLogin")
        if if_login != True:
            return "请登录"

if __name__ == "__main__":
    app.run()
